package string;

public class SyncApiDemo {
    public static void main(String[] args) {
        StringBuilder b=new StringBuilder();//适用于单线程
        //StringBuffer b=new StringBuffer();//多线程
        Thread t1=new Thread(){
            public void run(){
                for (int i=0;i<10000;i++) {
                    b.append("hello");
                }
            }
        };
        Thread t2=new Thread(){
            public void run(){
                for (int i=0;i<10000;i++) {
                    b.append("hello");
                }
            }
        };
        t1.start();
        t2.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(b.length());
    }
}
